<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
key=request.QueryString("key")
uid=request.QueryString("uid")
mark=request.QueryString("mark")
pay=request.QueryString("pay")
search=request.QueryString("search")
if search="搜索" then
	  if key<>"" then
			sqlsearch=" and (title like '%"&key&"%')"
	  end if
	  if uid<>"" then
			sqlsearch=sqlsearch+" and uid='"&uid&"'"
	  end if
	  if mark<>"" then
			sqlsearch=sqlsearch+" and mark="&mark&""
	  end if
end if
'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by id desc ) as sortid,* From inquiry) as TempTable where 1=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" [id],[Uid],[Pic],[Title],adminname,[url],[Qty],[Content],[Price],[Falg],[Addtime],sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<style>body {background-color: #eaece1;}</style>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var checkflag = "false";
function checkall(field) {
if (checkflag == "false") {
for (i = 0; i < field.length; i++) {
field[i].checked = true;}
checkflag = "true";}
else {
for (i = 0; i < field.length; i++) {
field[i].checked = false; }
checkflag = "false";	}
}
//end-->
</script>
</head>

<body>
<div class="main">
  <div class="main-title">查看 <a href="?add=yes">添加</a></div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center">
    <form name="form" method="get" action="">
    商品名
      <input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
     
     会员UID
      <input name="uid" type="text" id="uid" value="<%=uid%>" maxlength="50" />
     
    <select name="mark" id="mark">
      <option value="">状态</option>
      <option value="0" <%if mark="0" then response.Write " selected"%>>等待出价</option>
      <option value="1" <%if mark="1" then response.Write " selected"%>>已出价</option>
  </select>
    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><strong>选择</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">会员</span></strong></td>
    <td align="center" bgcolor="#FFFFFF">添加者</td>
    <td align="center" bgcolor="#FFFFFF"><strong>商品</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">备注</span></strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>数量</strong></td>
    <td align="center" bgcolor="#FFFFFF">价格</td>
    <td align="center" bgcolor="#FFFFFF"><strong>状态</strong></td>
    <td bgcolor="#FFFFFF">操作</td>
    <td bgcolor="#FFFFFF"><strong>添加时间</strong></td>
    </tr>
    <%do while not Rs.eof%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("id")%>" /></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("uid")%></td>
    <td align="center" bgcolor="#FFFFFF" style="width:200px"><%=rs("adminname")%></td>
    <td align="center" bgcolor="#FFFFFF" style="width:200px">
    
                    <%
					if rs("pic")<>"" then response.Write "<img src='"&rs("pic")&"' width='80' height='80'>"
					if rs("title")<>"" then response.Write "<br>"&rs("title")
					if rs("url")<>"" then response.Write "<br>"&rs("url")
					%>
    
    </td>
    <td align="center" bgcolor="#FFFFFF" style="width:300px"><%=rs("content")%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("Qty")%></td>
    <td align="center" bgcolor="#FFFFFF"><%if rs("price")="0" then response.Write "无" else response.Write rs("price")&"日元"%></td>
    <td align="center" bgcolor="#FFFFFF"><% 
	if rs("falg")=false then response.Write "<font color=red>等待出价</font>" 
	if rs("falg")=true then response.Write "<font color='#0000F0'>已出价</font>"
	%></td>
    <td bgcolor="#FFFFFF"><a href="../product/add.asp?inquiryID=<%=rs("id")%>&inquiry_pic=<%=rs("pic")%>&inquiry_title=<%=rs("title")%>">报价并发布</a></td>
    <td bgcolor="#FFFFFF"><%=rs("addtime")%></td>
    </tr>
    <%
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="10" align="center" bgcolor="#FFFFFF" class="page">
<input type="submit" name="button" id="button" value="删除" />

<!--<input type="submit" name="button" id="button" value="保存出价" />

      <input type="submit" name="button" id="button" value="等待出价">  
            <input type="submit" name="button" id="button" value="已出价">-->
      
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="10" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
    共 <%=Pager_TotalRecord%> 条 第<%=CurrentPage%>页 / 共 <%=Pager_PageCount%> 页
		<%
		pageurl="key="&key&"&uid="&uid&"&pay="&pay&"&mark="&mark&"&search="&search&"&"
		if CurrentPage=1 then
			response.Write(" 首页 ")
			response.Write(" 上一页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page=1'>首页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage-1) &"'>上一页</a> ")
		end if
		%>
		<%
		if Clng(CurrentPage)=Clng(Pager_PageCount) then
			response.Write(" 下一页 ")
			response.Write(" 尾页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage+1) &"'>下一页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& Pager_PageCount &"'>尾页</a> ")
		end if
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="mark" value="<%=mark%>" />
        <input type="hidden" name="uid" value="<%=uid%>" />
        <input type="hidden" name="pay" value="<%=pay%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
      </td>
    </tr>
  </table>
</div>
</div>









<%if request.QueryString("add")="yes" then%>
<div class="pop_contentx" style="width:600px">
<h2><a href = "<%=siteurl&"?"&pageurl&"page="&request.QueryString("page")&""%>">关闭</a>加入询价商品</h2>
<ul>
  <form action="inquirysave.asp" method="post" enctype="multipart/form-data" class="registerform dg_form_1">
  <table width="80%" border="0" cellspacing="0" cellpadding="4">
    <tr>
      <td>商品链接</td>
      <td><input type="text" name="url" value="<%=url%>" class="text" datatype="url" ignore="ignore" nullmsg="请输入商品链接！" errormsg="商品链接输入错误" /><span class="Validform_checktip"></span></td>
    </tr>
    <tr>
      <td>商品名</td>
      <td><input type="text" name="title" value="<%=title%>" class="text" datatype="*1-100" ignore="ignore" nullmsg="请输入商品名称！" errormsg="商品名称输入错误"  />
                        <span class="Validform_checktip"></span></td>
    </tr>
    <tr>
      <td>图片</td>
      <td><input type="file" name="pic" class="text text_1" datatype="/(JPG|GIF|PNG|jpg|gif|png)/" ignore="ignore" nullmsg="请选择图片！" errormsg="图片格式错误" />
						<span class="Validform_checktip"></span></td>
    </tr>
    <tr>
      <td>数量</td>
      <td><input type="text" name="qty" value="<%=qty%>" class="text text_1" datatype="n" nullmsg="请填写购买数量！" errormsg="数量输入错误" />
                        <span class="Validform_checktip"></span></td>
    </tr>
    <tr>
      <td>备注</td>
      <td><textarea class="ta_1" name="content" datatype="*1-500" ignore="ignore" nullmsg="请输入商品购买备注！" errormsg="备注字符1,500"><%=content%></textarea>
        <span class="Validform_checktip"></span></td>
    </tr>
    <tr>
      <td>UID</td>
      <td><input name="UID" type="text" class="text text_1" id="UID" value="<%=UID%>" datatype="*1-15" nullmsg="请填写会员uid！" errormsg="输入错误" />
      <span class="Validform_checktip"></span>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="r" id="button" value="提交" />
        <input type="hidden" name="t" value="add" />
        <input type="hidden" name="id" value="<%=edit%>" />
        <input type="hidden" name="back" value="inquiry.asp?add=yes" />
        </td>
    </tr>
  </table>
  </form>
</ul>

<h2>加入询价商品</h2>
<ul>
<form class="registerform" action="" method="post">
<table width="100%">
				<tr>
					<th align="left"><input type="checkbox" name="checkbox2" onClick="javascript:checkall(this.form);" /> 全选</th>
					<th>图片</th>
					<th>备注</th>
					<th>购买数量</th>				
					<th>操作</th>				
				</tr>
                
                
                <%		
				set rsnewx=server.CreateObject("adodb.recordset")
				sql="select * from InquiryCart where adminname='"&request.cookies("admin")("name")&"' order by id"
				rsnewx.open sql,conn,1,3
				if not rsnewx.eof then
				do while not rsnewx.eof 
				%>
				<tr>
					<td align="left"><input type="checkbox" name="checkbox" value="<%=rsnewx("id")%>" onClick="javascript:checkall(this.form);" /></td>
					<td align="center">
                    
                    <%
					if rsnewx("pic")<>"" then response.Write "<img src='"&rsnewx("pic")&"' width='80' height='80' alt='' class='mtb10'>"
					if rsnewx("title")<>"" then response.Write "<br>"&rsnewx("title")
					if rsnewx("url")<>"" then response.Write "<br>"&rsnewx("url")
					%>
                    
                    
                    </td>
					<td align="center"><%=rsnewx("content")%></td>
					<td align="center"><%=rsnewx("qty")%></td>
					<td align="center"><a href="?del=<%=rsnewx("id")%>" class="gray_u">删除</a>&nbsp;&nbsp;&nbsp;<a href="?edit=<%=rsnewx("id")%>" class="gray_u">修改</a></td>
				</tr>
                <%
				rsnewx.movenext
				loop
				rsnewx.close
				set rsnewx=nothing
				end if		 
				%>
                <tr>
					<th colspan="5" align="center"><input type="submit" name="r" id="button" value="提交" />
                    <input type="hidden" name="t" value="y" />
                    </th>
				</tr>
			</table>
</form>
</ul>




</div> 
<div class="pop_bgx"></div> 
<%end if%>
















<link rel="stylesheet" href="/Validform/css/style.css" type="text/css" media="all" />
<script type="text/javascript" src="/Validform/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="/Validform/js/Validform_v5.3.2_min.js"></script>
<script type="text/javascript">
$(function(){
	//$(".registerform").Validform();  //就这一行代码！;
		
	$(".registerform").Validform({
		btnSubmit:".btn_sub", 
		//btnReset:".btn_reset",
		//tiptype:1, 
		showAllError:true,
		tiptype:function(msg,o,cssctl){
			//msg：提示信息;
			//o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
			//cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
			if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
				var objtip=o.obj.siblings(".Validform_checktip");
				cssctl(objtip,o.type);
				objtip.text(msg);	
			}
		}
	});
})
</script>








</body>
</html>



<%
'添加
if request.Form("t")="y" then
  
  checkbox=request.Form("checkbox")
  
  if checkbox="" then
  response.write"<script>alert('请选择商品');</script>"
  response.write"<script>window.history.back(-1);</script>"
  response.end
  end if

  set rslistx=server.CreateObject("adodb.recordset")
  sql="select * from inquiryCart where adminname='"&request.cookies("admin")("name")&"' and id in("&checkbox&")"
  rslistx.open sql,conn,1,3
  if not rslistx.eof then
  do while not rslistx.eof
  '产品写入
		Set rsdetail=server.createobject("adodb.recordset")
		rsdetail.Open "select * from inquiry" ,conn,2,3
		rsdetail.AddNew 
		rsdetail("uid")=rslistx("uid")   '会员ID
		rsdetail("url")=rslistx("url") 
		rsdetail("title")=rslistx("title") 
		rsdetail("pic")=rslistx("pic") 
		rsdetail("qty")=rslistx("qty") 
		rsdetail("content")=rslistx("content") 
		rsdetail("adminname")=request.cookies("admin")("name")
		rsdetail.Update
		rsdetail.close
		set rsdetail=nothing
  rslistx.movenext
  loop
  rslistx.close
  set rslistx=nothing
  end if
  
  conn.execute("delete from inquiryCart where adminname='"&request.cookies("admin")("name")&"' and id in("&checkbox&")")
  response.Redirect "inquiry.asp"
end if


'删除
if request.QueryString("del")<>"" then
conn.execute("delete from inquiryCart where adminname='"&request.cookies("admin")("name")&"' and id="&request.QueryString("del")&"")
response.Redirect "inquiry.asp"
end if
%>





<%
checkbox=request.Form("checkbox")
if checkbox<>"" then	
	if request.Form("button")="删除" then
		conn.execute("delete from inquiry where id in("&checkbox&")")

	elseif request.Form("button")="保存出价" then
	    '保存价格
		
		
		 id=replace(checkbox," ","")
         id=Split(id,",")

        For i=LBound(id) To UBound(id) 
        Set rs = Server.CreateObject("ADODB.Recordset")
        sql= "Select * from inquiry where id ="&id(i)&""
        rs.open sql,conn,1,3
        rs("price")=request.Form("price"&id(i))
        rs.Update
        Next
		
		
		
		
		conn.execute("update inquiry set mark=1 where id in ("&checkbox&")")
	
	elseif request.Form("button")="等待出价" then
		conn.execute("update inquiry set mark=0 where id in ("&checkbox&")")
		
	elseif request.Form("button")="已出价" then
		conn.execute("update inquiry set mark=1 where id in ("&checkbox&")")
	
	end if
	response.Redirect "inquiry.asp?page="&request.QueryString("page")&""
end if
%>